import * as ActionTypes from './action-types';
import { combineReducers, AnyAction } from 'redux';

// 但从未读取其值   后面没用到  引入没必要 ts   
// tree-sharking

const initState = {
    loading: true,
    // 分支
    home: {
        partitions: {}
    },
    search: {
        suggest: [],
        hotword: [],
        searchResult: {}
    }
}
const combineSearch = (state = initState.search, action:AnyAction) => {
    switch(action.type) {
        case ActionTypes.SET_HOTWORD:
            return {
                ...state,
                hotword: action.data
            }
            break;
        case ActionTypes.SETSUGGEST:
            return {
                ...state,
                suggest: action.data
            }
        case ActionTypes.SET_SEARCHRESULT:
            return {
                ...state,
                searchResult: action.data
            }
        default:
            return state
    }
}
const combineLoading = (state = initState.loading, action:AnyAction) => {
    switch(action.type) {
        default:
            return state
    }
}
const combineHome = (state = initState.home, action: AnyAction) => {
    switch(action.type) {
        case ActionTypes.SET_PARTITIONS:
            return {
                ...state.partitions,
                partitions: action.data
            }
        break;
        default:
            return state
    }
}
export default combineReducers({
    search: combineSearch,
    loading: combineLoading,
    home: combineHome
})